<template>
    <div>
        <van-nav-bar title="订单" left-text="返回" left-arrow @click-left="onClickLeft" />

        <van-collapse v-model="orders" v-for="(order, index) in orders">
            <van-collapse-item :title="order.order_time" :name="index">
                <van-cell :title="order.user" icon="manager" />
                <van-cell :title="order.tel" icon="phone" />
                <van-cell :title="order.address" icon="location" />
                <van-cell :title="order.total_price" icon="gold-coin" />
                <span v-for="product in order.list">
                    <van-card :num="product.pnum" :price="product.price" desc="" :title="product.tname"
                    :thumb="product.fullSrc" />
                </span>
                

            </van-collapse-item>
        </van-collapse>
        <!-- <van-button @click="login">登录</van-button> -->
    </div>
</template>

<script setup lang='ts'>
import { ref, onMounted } from 'vue';
import { useRouter } from 'vue-router'
import { getMyOrder } from '../../api/server'

const router = useRouter()
const orders = ref(['1']);

// 加载钩子
onMounted(() => {
    getOrder();
    //   let data=getMyOrder();
    //   console.log(data)
});

// 获取订单数据
const getOrder = async () => {
    try {
        const response = await getMyOrder();
        // console.log("订单数据获取成功：", response);
        if (response.data.code === 200 && response.data.data) {
            orders.value = response.data.data as Product[];
        }
    } catch (error) {
        // console.error("获取订单数据失败:", error);
    }
};



function onClickLeft() {
    router.go(-1)
}

function login() {

}
</script>

<style scoped></style>